<script setup lang="ts">
import {onMounted, ref} from "vue";
import * as echarts from 'echarts';

let ageRateRef = ref();
onMounted(() => {
  let ageChart = echarts.init(ageRateRef.value);
  ageChart.setOption({
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: 20,
      right: 40,
      orient: 'vertical', // 图例的放置方式
      textStyle: {
        color: "white"
      }
    },
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['30%', '60%'], // 内半径，外半径
        center: ['30%',"40%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [
          {value: 1048, name: 'Search Engine'},
          {value: 735, name: 'Direct'},
          {value: 580, name: 'Email'},
          {value: 484, name: 'Union Ads'},
          {value: 300, name: 'Video Ads'}
        ]
      }
    ]
  });
})
</script>

<template>
  <div class="age-rate">
    <div class="title">年龄比例</div>
    <div class="age-chart" ref="ageRateRef"></div>
  </div>
</template>

<style scoped lang="scss">
.age-rate {
  flex: 1.5;
  background-color: hotpink;
  margin: 10px;
  .title {
    font-size: 20px;
    color: white;
  }
  .age-chart {
    width: 100%;
    height: 300px;
  }
}
</style>